<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "classify".
 *
 * @property int $id id
 * @property string $name 名称
 */
class Classify extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'classify';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'name' => Yii::t('app', 'Name'),
        ];
    }

    public function getProducts()
    {
        return $this->hasMany(Product::class,['classify_id'=>'id']);
    }

    public function extraFields()
    {
        return array_merge(parent::extraFields(), [
            'products',
        ]); // TODO: Change the autogenerated stub
    }
}
